const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
const WebpackMerge = require('webpack-merge')
module.exports = {
  mode: 'development',
  cache: true,
  devtool: 'inline-source-map',
  entry: './src/index.js',
  optimization: {
    usedExports: true,
  },
  devServer: {
    contentBase: path.resolve(__dirname, 'dist'),
    open: 'http://127.0.0.1:9000',
    host: '0.0.0.0',
    port: '9000',
    hot: true,
    stats: 'errors-only',
    publicPath: '/'
  },
  output: {
    filename: '[name].[contenthash].js',
    path: path.resolve(__dirname, 'dist'),
    clean: true
  },
  module: {
    rules: [
      // {
      //   test: /\.js$/,
      //   include: path.resolve(__dirname, 'src'),
      //   loader: 'babel-loader',
      // },
      {
        test: /\.css$/i,
        use: ['style-loader', 'css-loader'],
      },
      {
        test: /\.(png|svg|jpg|jpeg|gif)$/i,
        type: 'asset/resource',
        // loader: 'url-loader?limit=1000&name=images/[hash:8].[name].[ext]'
      },
      {
        test: /\.(woff|woff2|eot|ttf|otf)$/i,
        type: 'asset/resource',
      },
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      title: '管理输出',
    }),
    new webpack.HotModuleReplacementPlugin({
      // Options...
    }),
    new webpack.ProvidePlugin({
      _: 'lodash',
    }),
    new FriendlyErrorsPlugin({
      compilationSuccessInfo: {
        messages: ['`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`'],
      },
      // onErrors: config.dev.notifyOnErrors
      // ? utils.createNotifierCallback()
      // : undefined
    })
  ],
};